#include "ModelTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION (ModelTest); 

void ModelTest :: setUp (void)
{

	model= new SketchModel();

	model->addLine(Coordinate(10.1,20.1),Coordinate(15.1,11.1));
	std::list<Coordinate> cpoin;
	cpoin.push_back(Coordinate(10.,31.));
	cpoin.push_back(Coordinate(20.,41.));
	cpoin.push_back(Coordinate(60.,81.));
	cpoin.push_back(Coordinate(80.,91.));
	model->addSegment(cpoin);
	model->addLine(Coordinate(10.,20.),Coordinate(15.,11.));
	model->addFixPoint(1);
	model->addHorizontal(3,4);
	model->addConnectPoints(2,5);

/*	try{

	}catch(MyException e){
		e.print();
	}*/

}

void ModelTest :: tearDown (void) 
{
	delete model;

}


void ModelTest :: testFunction (void)
{

}
void ModelTest :: testFunction2 (void)
{
	std::cout << model->report() << std::endl;
	model->solve();
	std::cout << model->report() << std::endl;

}
void ModelTest :: testFunction4 (void)
{
	std::cout << model->report() << std::endl;
	// TABLE DATA
	std::map<int,std::string> prims = model->getPrimitiveData();
	std::list<ConstraintData> cons = model->getConstraintData();


	std::cout << "Primitives: " << std::endl;
	for(std::map<int,std::string>::iterator it = prims.begin(); it!= prims.end(); it++){
		std::cout << it->first << "- " << it->second << std::endl;
		std::map<int,Coordinate> pnt = model->getPrimitivePoints(it->first);
		for(std::map<int,Coordinate>::iterator itp=pnt.begin(); itp!= pnt.end(); itp++){
			std::cout << itp->first << "- "<< itp->second.x << "," << itp->second.y << std::endl;
		}
	}
	std::cout << "Constraint: " << std::endl;
	for(std::list<ConstraintData>::iterator it = cons.begin(); it!=cons.end(); it++){
		std::cout << it->type  << "- " <<
				it->id  << "- " <<
				it->idK  << "- " <<
				it->idL  << "- " <<
				it->idM  << "- " <<
				it->idN  << "- " <<
				it->paramId  << "- "  << std::endl;
	}

	/** Male ZMiany */
	model->removePrimitive(1);
	std::cout << model->report() << std::endl;
	model->removeConstraint(2);
	std::cout << model->report() << std::endl;
	std::list<Coordinate> pn;
	pn.push_back(Coordinate(56.,65.));
	pn.push_back(Coordinate(156.,165.));
	pn.push_back(Coordinate(256.,265.));
	model->addSegment(pn);
	model->addConnectPoints(8,10);
	std::cout << model->report() << std::endl;
	/** ***********************************/
	std::cout << "***********************************" << std::endl;
	std::map<int,std::string> prims2 = model->getPrimitiveData();
	std::list<ConstraintData> cons2 = model->getConstraintData();


	std::cout << "Primitives: " << std::endl;
	for(std::map<int,std::string>::iterator it = prims2.begin(); it!= prims2.end(); it++){
		std::cout << it->first << "- " << it->second << std::endl;
		std::map<int,Coordinate> pnt = model->getPrimitivePoints(it->first);
		for(std::map<int,Coordinate>::iterator itp=pnt.begin(); itp!= pnt.end(); itp++){
			std::cout << itp->first << "- "<< itp->second.x << "," << itp->second.y << std::endl;
		}
	}
	std::cout << "Constraint: " << std::endl;
	for(std::list<ConstraintData>::iterator it = cons2.begin(); it!=cons2.end(); it++){
		std::cout << it->type  << "- " <<
				it->id  << "- " <<
				it->idK  << "- " <<
				it->idL  << "- " <<
				it->idM  << "- " <<
				it->idN  << "- " <<
				it->paramId  << "- " << std::endl;
	}

}
